#ifndef UTILS_H_
#define UTILS_H_

#include <s32mem.h>

namespace scatu {

enum TReturnTypeDesignator { EReturnTypeDesignator };

template<typename T>
class MFunctor
    {
public:
    virtual void operator()(T) = 0;
    };

template<>
class MFunctor<void>
    {
public:
    virtual void operator()() = 0;
    };

class RStreamWriteHelper
    {
public:
    RBufWriteStream & OpenStreamL()
        {
        iStreamBuf = CBufFlat::NewL(512);
        iStream.Open(*iStreamBuf);
        return iStream;
        }
    
    HBufC8 * FinalizeStreamL()
        {
        iStream.Close();
        HBufC8 * buffer = HBufC8::NewL(iStreamBuf->Size());
        TPtr8 pData(buffer->Des());
        iStreamBuf->Read(0, pData, iStreamBuf->Size());
        
        delete iStreamBuf;
        iStreamBuf = NULL;
        
        return buffer;
        }
    
    void Close()
        {
        iStream.Close();
        delete iStreamBuf;
        iStreamBuf = NULL;
        }
    
private:
    CBufFlat * iStreamBuf;
    RBufWriteStream iStream;
    };

} // namespace scatu

#endif /* UTILS_H_ */
